package disenio

import modelo.*
import org.uqbar.arena.bindings.NotNullObservable
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.layout.HorizontalLayout
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.widgets.TextBox
import org.uqbar.arena.widgets.tables.Column
import org.uqbar.arena.widgets.tables.Table
import org.uqbar.arena.windows.Dialog
import org.uqbar.arena.windows.SimpleWindow
import org.uqbar.arena.windows.WindowOwner
import org.uqbar.arena.widgets.Selector
import org.uqbar.arena.bindings.ObservableProperty
import org.uqbar.arena.bindings.PropertyAdapter
import modelo.Sistema

class JardinZenWindow extends Dialog<Jugador> {

	new(WindowOwner owner, Jugador jugador) {
		super(owner, jugador)
	}

	
	
	
	

	override protected createFormPanel(Panel mainPanel) {
		val form = new Panel(mainPanel)
		this.createJardinZenGrid(mainPanel)
		
		
//		val selectorModelo = new Selector<Planta>(form)
//		selectorModelo.allowNull(false)
//		selectorModelo.bindValueToProperty("jardinZenTierra")
//		var nombreDePlanta = selectorModelo.bindItems(new ObservableProperty(modelObject, "jardinZenTierra"))
//		nombreDePlanta.adapter = new PropertyAdapter(typeof(Planta), "nombre")
		
		
		
	}
	
	def createJardinZenGrid(Panel mainPanel) {
		
		var tableT = new Table<Planta>(mainPanel, typeof(Planta))
		tableT.heigth = 200
		tableT.width = 450
		tableT.bindItemsToProperty("jardinZenTierra")
		tableT.bindValueToProperty("plantaSeleccionada")
		//modelObject.jardin.filas.forEach[f|f.getPlantasAll]
		//modelObject.jardin.filas.forEach[f|f.getPlantas]
		
		this.describeJardinZenGrid(tableT)
		
		
		var tableA = new Table<Planta>(mainPanel, typeof(Planta))
		tableA.heigth = 200
		tableA.width = 450
		tableA.bindItemsToProperty("jardinZenAgua")
		tableA.bindValueToProperty("plantaSeleccionada")
		this.describeJardinZenGrid(tableA)
		
	}
	
	def describeJardinZenGrid(Table<Planta> table) {
//		throw new UnsupportedOperationException("TODO: auto-generated method stub")
		
		new Column<Planta>(table) //
			.setTitle("Plantas")
			.setFixedSize(100)
			.bindContentsToProperty("nombre")
			
		new Column<Planta>(table) //
			.setTitle("Daño")
			.setFixedSize(100)
			.bindContentsToProperty("danio")
					
		new Column<Planta>(table) //
			.setTitle("Resistencia")
			.setFixedSize(100)
			.bindContentsToProperty("resistencia")
			
			
	}

	override protected void addActions(Panel actions) {
		new Button(actions)
			.setCaption("Mejorar")
			//.onClick [|this.atacar]
			//.setAsDefault.disableOnError

		new Button(actions) //
			.setCaption("Cancelar")
			.onClick [|this.cancel]
	}
	
	
	
	
	
	
	
	
	

}
